﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JsAndSilverLight.Web.google卫星地图抓取
{
    public partial class 请求 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            WebClient wc = new WebClient();
            打开google地图(wc);


            打开google地图2(wc);

            //wc.Headers.AllKeys

        }

        void 打开google地图2(WebClient wc)
        {

            wc.DownloadString("http://mt0.google.cn/vt?lyrs=s@159&hl=zh-CN&gl=CN&x=26830&y=13028&z=15&token=99917");
            Response.Write(string.Join(";", wc.ResponseHeaders));
        }

        void 打开google地图(WebClient wc1)
        {
            WebClient wc = new WebClient();
            wc.DownloadString("http://ditu.google.cn/maps?output=classic&dg=ctry");
            Response.Write(string.Join(";", wc.ResponseHeaders));

            var setcookies = wc.ResponseHeaders.Cast<string>()
                 .Where(p => p.ToLower().Contains("set-cookie"))
                 .Select(p => new { key = p, Val = wc.ResponseHeaders[p] })
                 .ToList();



            foreach (var item in setcookies)
            {
                wc1.Headers.Add("Cookie", item.Val.Split(';')[0]);
            }

        }
    }
}